﻿using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Generic;
using Assets.Scripts.Net;
using Assets.Scripts.Net.Data.Model;
using Assets.Scripts.Tool;
using Assets.Scripts.UI.Buttons;
using Assets.Scripts.UI.Item;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;
using Random = System.Random;

namespace Assets.Scripts.UI.Panel
{
    public enum ExamType
    {
        Null = -1,
        HomeWork = 0, //课后作业
        Mock = 1, //模拟考试
        Exam = 2, //正常考试
        WrongExercise = 3 //错题练习
    }

    public enum TitleType
    {
        单项选择题,
        多项选择题,
        判断题,
        填空题,
        简答题
    }

    /// <summary>
    ///     存储题型的信息
    /// </summary>
    public class TitleInfo
    {
        public string Name { get; set; } //题型名称
        public float? Score { get; set; } //每小题的分数（从整数该为小数）
        public int Count { get; set; } //本题型具有的题目数量
        public float SingleScore { get; set; } //选对一个的分数 
    }

    /// <summary>
    ///  考试的Panel
    /// </summary>
    public class ExamPanel : UIBase<ExamPanel>
    {
        //组件
        public Text TimeText; //倒计时的文本
        public Text ExamName; //考试名称
        public Text ScoreText; //分数
        public Transform Content_Guide; //题目导航按钮的Content
        public Transform TimeObj; //时间
        public Transform ExamLable; //考试 
        public Transform ScoreLable; //分数表
        public Transform CheckLable; //查询成绩
        public Transform SubmitPaperMask;//必须提交试卷的遮罩
        public Transform FullScreenParent; //遮罩（避免全屏模式下点击到其他按钮）        
        public ScrollRect ScrollView_Paper; //试卷Rect
        public ScrollRect ScrollView_Guide; //导航Rect

        public Button SubmitButton; //提交按钮
        public Button MustSubmitButton;//必须提交试卷的按钮
        public Button ExitButton; //退出按钮
        public Button SettingButton; //设置按钮
        public Button PageButton; //分页按钮
        public Button UserInfoButton;//用户信息按钮
        public Button TestSubmitButton;// 试题测试 
        public Button RandomAnswerButton;//随机填写题目

        public static event Action OnRandomAnswer;

        //属性
        public List<AnsInfo> AnsInfos { get; set; }
        public List<QueInfo> QueInfos { get; set; }
        public List<AnsInfo> RamdonedAnsInfos { get; set; } //随机后得到的答案信息
        public List<PaperGuideItem> GuideItems { get; set; } //试卷导航的Item
        public List<QueVideoItem> VideoItems { get; set; } //存储问题的播放器Item
        public List<QueAudioItem> AudioItems { get; set; } //音频的Item        
        public float DownLoadProgress { get; set; } //加载资源的速度

        public Ease Ease;

        public float EaseTime;

        private float examTime; //考试的时间

        private bool isSubmit; //是否已经提交试卷

        private bool isInit; //判断是否已经初始化

        private bool stopTimer;//停止计时器

        private ExamType examType; //考试的类型

        private int? examId; //考试的id

        private Dictionary<string, object> submitPaperInfo; //传回服务器的字典

        private Action<float> OnSubmitPaper; //提交试卷的回调

        public List<Transform> scrollView_Papers = new List<Transform>(); //分页的scrollView

        public List<Button> pageButtons = new List<Button>(); //分页按钮
      
        private Transform nowPage { get; set; } //当前选择的页面
        private Button nowClickButton { get; set; } //当前点击的页面按钮 

        private readonly int pageQueNum = 15; //每一页的题目数量 现在暂定为30道题
        private int queType { get; set; } //存储当前的问题的类型
        private bool isCheckScore { get; set; }//是否是检查分数
        private List<string> titleTypes { get; set; } //存储大题的类型
        public List<TitleInfo> titleInfos { get; set; } //大题题目类型信息


        public delegate void OnUpdateScoreEvent(ExamType examType,float score, int id);

        public static OnUpdateScoreEvent OnUpdateScore;

        protected override UIType UIType
        {
            get { return UIType.Panel; }
        }

        public static ExamPanel _Instance;

        protected override void InitOnDestroy()
        {
            _Instance = null;
            LoginTimeOutPanel.OnLoginTimeOut -= LoginTimeOut;
        }

        protected override void InitOnAwake()
        {
            _Instance = this;
            AutoFindComponent(transform, true);
            ExitButton.onClick.AddListener(OnExitButton);
            SubmitButton.onClick.AddListener(OnSubmitButtonClick);
            MustSubmitButton.onClick.AddListener(()=>{StartCoroutine(SubmitPaper()); });
            SettingButton.onClick.AddListener(() => { CreatePanel(PanelType.SettingPanel); });
            FullScreenParent.gameObject.SetActive(false);
            RamdonedAnsInfos = new List<AnsInfo>();
            GuideItems = new List<PaperGuideItem>();
            AudioItems = new List<QueAudioItem>();
            VideoItems = new List<QueVideoItem>();
            submitPaperInfo = new Dictionary<string, object>();
            queType = -1; //初始化问题的类型
            titleTypes = new List<string>();
            titleInfos = new List<TitleInfo>();
            TestSubmitButton.onClick.AddListener(SubmitPaperTest);
            TestSubmitButton.gameObject.SetActive(false);
            RandomAnswerButton.gameObject.SetActive(false);
            UserInfoButton.onClick.AddListener(() =>
            {
                CreatePanel(PanelType.StudentInfoPanel);
            });
#if TEST
            TestSubmitButton.gameObject.SetActive(true);
            RandomAnswerButton.gameObject.SetActive(true);
            RandomAnswerButton.onClick.AddListener(() =>
            {
                if (OnRandomAnswer != null)
                {
                    OnRandomAnswer();
                }
            });
#endif
            LoginTimeOutPanel.OnLoginTimeOut += LoginTimeOut;            
        }

        private void OnExitButton()
        {
            if (examType == ExamType.Exam)
            {
                UIManager._Instance.ShowTipInfo("正式考试，未提交试卷将不能退出考试");
                //CreatePanel(PanelType.MainPanel);s
            }
            else
            {
                for (var i = 0; i < QueInfos.Count; i++)
                {
                    QueInfos[i].questate = 0;
                }
                Exit();
            }
        }

  

        /// <summary>
        ///     关闭视频的播放
        /// </summary>
        private void CloseVideoPlay()
        {
            for (var i = 0; i < VideoItems.Count; i++)
            {
                if (VideoItems[i].VideoSeekBar.isPlay)
                {
                    VideoItems[i].PauseButton.onClick.Invoke();
                }
            }
        }

        /// <summary>
        ///     关闭音频的播放
        /// </summary>
        private void CloseAudioPlay()
        {
            for (var i = 0; i < AudioItems.Count; i++)
            {
                if (AudioItems[i].Audio.isPlaying)
                {
                    AudioItems[i].PauseButton.onClick.Invoke();
                    AudioItems[i].PauseButton.onClick.Invoke();
                }
            }
        }

        public void StopMediaPlay()
        {
            CloseAudioPlay();
            CloseVideoPlay();
        }

        protected override void InitOnDisable()
        {
            ClearData();
        }

        /// <summary>
        /// 清理数据
        /// </summary>
        public void ClearData()
        {           
            if(isCheckScore)
                return;
            if (AnsInfos != null)
            {
                for (int i = 0; i < AnsInfos.Count; i++)
                {
                    AnsInfos[i].ischoose = false;
                }
            }
            if (QueInfos != null)
            {
                for (int i = 0; i < QueInfos.Count; i++)
                {
                    //todo nothing
                }
            }
            
        }

        /// <summary>
        ///     提交试卷
        /// </summary>
        public IEnumerator SubmitPaper()
        {
            //if (isSubmit) //如果已经提交试卷
            //{
            //    NetManager.Instance.SendRequest(RequestType.SubmitPaper, submitPaperInfo, () =>
            //    {
            //        //显示分数界面并且退出该界面                     
            //        var panel = CreatePanel(PanelType.ExamReslutPanel).GetComponent<ExamReslutPanel>();
            //        panel.Init((int) submitPaperInfo["objscore"], (int) submitPaperInfo["subscore"],
            //            (int) submitPaperInfo["subunknow"], (int) submitPaperInfo["totalscore"], examType);
            //    });
            //    yield return null;
            //}
            var tsf = CreatePanel(PanelType.LoadingLoopPanel);
            tsf.GetComponent<LoadingLoopPanel>().Init();
            //isSubmit = true;
            var objScore = 0.0f; //客观题目得分
            var subScore = 0.0f; //主观题得分
            var subUnKnow = 0.0f; //主观题未改分数
            var totalScore = 0.0f; //当前总分
            var ids = "0"; //当前做题的id
            for (var i = 0; i < QueInfos.Count; i++)
            {
                //Debug.Log("问题的类型：" + QueInfos[i].quetype);
                List<AnsInfo> ansInfos;
                if (QueInfos[i].quetype == 0 || QueInfos[i].quetype == 2 || QueInfos[i].quetype == 5|| QueInfos[i].quetype == 7) //客观题: 单选，判断，随机单选，公式题
                {
                    if (QueInfos[i].ansdata == null)
                    {
                        QueInfos[i].ansdata = GetAnsInfosByQueId(QueInfos[i].id, true);
                    }
                    ansInfos = QueInfos[i].ansdata;
                    QueInfos[i].ischeck = 1;
                    //判断题目的格式是否正确
                    var isRight = QueInfos[i].quetype == 0 || QueInfos[i].quetype == 2 ||
                                  ansInfos.Count >= 4 &&
                                  (QueInfos[i].quetype == 5 || QueInfos[i].quetype == 7);
                    //Debug.Log("题目的格式是否正确："+isRight);
                    for (var j = 0; j < ansInfos.Count; j++)
                    {
                        if (ansInfos[j].ischoose != Convert.ToBoolean(ansInfos[j].isright))
                        {
                            isRight = false;
                            break;
                        }
                    }
                    if (isRight)
                    {
                        //Debug.LogError("答对题目的id:"+QueInfos[i].id+QueInfos[i].content);
                        objScore += Convert.ToSingle(QueInfos[i].score);//修改，分数类型改为float
                        ids += ";" + QueInfos[i].id;
                    }
                    QueInfos[i].isright = Convert.ToInt32(isRight);
                }
                else if (QueInfos[i].quetype == 1 || QueInfos[i].quetype == 6) //多选题的判断
                {
                    if (QueInfos[i].ansdata == null)
                    {
                        QueInfos[i].ansdata = GetAnsInfosByQueId(QueInfos[i].id, true);
                    }
                    Debug.Log("单项得分是：" + QueInfos[i].singlescore);
                    ansInfos = QueInfos[i].ansdata;
                    var isRight = ansInfos.Count >= 4;
                    var isAllRight = true; //是否全选对了
                    float score = 0; //得分
                    for (var j = 0; j < ansInfos.Count; j++)
                    {
                        if (ansInfos[j].isright == 0 && ansInfos[j].ischoose)
                        {
                            //说明选择了错误的答案
                            isRight = false;
                            isAllRight = false;
                            break;
                        }
                        if (ansInfos[j].isright == 1 && ansInfos[j].ischoose == false)
                        {
                            isAllRight = false; //没有全选对
                        }
                        if (ansInfos[j].isright == 1 && ansInfos[j].ischoose)
                        {
                            score += QueInfos[i].singlescore;
                        }
                    }
                    if (isAllRight && isRight) //全对
                    {
                        objScore += Convert.ToSingle(QueInfos[i].score);//修改，分数类型改为float
                        ids += ";" + QueInfos[i].id;
                    }
                    else if (!isAllRight && isRight) //选择了部分答案
                    {
                        objScore += score;
                    }
                    QueInfos[i].isright = Convert.ToInt32(isAllRight);
                    Debug.LogWarning("是否全对:" + Convert.ToInt32(isAllRight));
                }
                else //主观题，填空，简答
                {
                    if (QueInfos[i].ansdata == null)
                    {
                        QueInfos[i].ansdata = GetAnsInfosByQueId(QueInfos[i].id, true);
                    }
                    ansInfos = QueInfos[i].ansdata;
                    if (ansInfos.Count > 0 && ansInfos[0].content != null && ansInfos[0].content == ansInfos[0].userans &&
                        ansInfos[0].ischoose)
                    {
                        QueInfos[i].ischeck = 1;
                        QueInfos[i].isright = 1;
                        ids += ";" + QueInfos[i].id;
                        subScore += Convert.ToSingle(QueInfos[i].score);//修改，分数类型改为float
                    }
                    else
                    {
                        QueInfos[i].ischeck = 0;
                        subUnKnow += Convert.ToSingle(QueInfos[i].score);//修改，分数类型改为float
                    }
                }
                yield return new WaitForEndOfFrame();
            }
            totalScore = objScore + subScore;
            var dict = NetManager.Instance.GetDict();
            if (examType != ExamType.WrongExercise)
            {
                //发送分数
                //dict.Add("objscore", objScore);
                //dict.Add("subscore", subScore);
                //dict.Add("subunknow", subUnKnow);
                //发送当前的总分
                dict.Add("totalscore", totalScore);
                //添加试卷信息
                dict.Add("examname", ExamName.text);
                dict.Add("examid", examId);
                dict.Add("quedata", ClearnQueInfos(QueInfos, ClearnAnsInfos(RamdonedAnsInfos)));
                dict.Add("type", (int) examType);
                submitPaperInfo = dict;
                NetManager.Instance.SendRequest(RequestType.SubmitPaper, dict, () =>
                {
                    Destroy(tsf.gameObject);
                    //显示分数界面并且退出该界面 
                    var panel = CreatePanel(PanelType.ExamReslutPanel).GetComponent<ExamReslutPanel>();
                    panel.Init(objScore, subScore, subUnKnow, totalScore, examType);
                    if (OnSubmitPaper != null)
                    {
                        OnSubmitPaper(totalScore);
                    }
                });
                if (OnUpdateScore != null)
                {
                    OnUpdateScore(examType, totalScore, (int) examId);
                }
            }
            else //错题练习
            {
                dict.Add("id", ids);
                if (CollectPanel._Instance.AutoRemoveToggle.isOn)
                {
                    NetManager.Instance.SendRequest(RequestType.ClearErrorList, dict, () =>
                    {
                        //显示分数界面并且退出该界面 
                        Destroy(tsf.gameObject);
                        var panel = CreatePanel(PanelType.ExamReslutPanel).GetComponent<ExamReslutPanel>();
                        panel.Init(objScore, subScore, subUnKnow, totalScore, examType);
                        //todo 删除本地的数据
                        CollectPanel._Instance.OnExercise(ids);
                    });
                }
                else
                {
                    Destroy(tsf.gameObject);
                    var panel = CreatePanel(PanelType.ExamReslutPanel).GetComponent<ExamReslutPanel>();
                    panel.Init(objScore, subScore, subUnKnow, totalScore, examType);
                }
            }
        }


        /// <summary>
        ///     清空问题集合的不必要的信息并返回新的集合
        /// </summary>
        private List<QueInfo> ClearnQueInfos(List<QueInfo> questions, List<AnsInfo> ansInfos)
        {
            var queInfos = new List<QueInfo>();
            for (var i = 0; i < questions.Count; i++)
            {
                var info = new QueInfo();
                info.id = questions[i].id;
                info.content = questions[i].quetype == 7 ? questions[i].content : null;
                info.ischeck = questions[i].ischeck;
                info.isright = questions[i].isright;
                info.iscollect = questions[i].iscollect;
                info.score = questions[i].score;
                info.isselect = questions[i].isselect;
                questions[i].ischeck = 0;
                questions[i].iscollect = 0;
                questions[i].questate = 0;
                //嵌套添加答案数据
                info.ansdata = new List<AnsInfo>();
                for (var j = 0; j < ansInfos.Count; j++)
                {
                    //Debug.Log("答案的问题id："+ansInfos[i].queid);
                    if (ansInfos[j].queid == info.id)
                    {
                        info.ansdata.Add(ansInfos[j]);
                    }
                }
                queInfos.Add(info);
            }
            return queInfos;
        }


        /// <summary>
        ///     清空答案集合的不必要信息并返回新的集合
        /// </summary>
        /// <param name="answers"></param>
        /// <returns></returns>
        private List<AnsInfo> ClearnAnsInfos(List<AnsInfo> answers)
        {
            var ansInfos = new List<AnsInfo>();
            for (var i = 0; i < answers.Count; i++)
            {
                var info = new AnsInfo();
                if (answers[i].id == 0) //判断题 或者 选择题
                {
                    if (answers[i].content == "正确" || answers[i].content == "错误")
                    {
                        continue;
                    }
                    info.content = answers[i].content;
                }
                info.id = answers[i].id;
                info.queid = answers[i].queid;
                info.ischoose = answers[i].ischoose;
                info.userans = answers[i].userans;
                info.isright = answers[i].isright;
                if (string.IsNullOrEmpty(answers[i].content) && !string.IsNullOrEmpty(answers[i].respath))
                {
                    answers[i].content = answers[i].respath;
                }
                answers[i].userans = null;
                ansInfos.Add(info);
            }
            return ansInfos;
        }

        private int successNum = 0;
        private int failedNum = 0;
        private IEnumerator testSubmit()
        {
            successNum = failedNum = 0;
            var tsf = CreatePanel(PanelType.LoadingLoopPanel);
            tsf.GetComponent<LoadingLoopPanel>().Init();
            //isSubmit = true;
            var objScore = 0.0f; //客观题目得分
            var subScore = 0.0f; //主观题得分
            var subUnKnow = 0.0f; //主观题未改分数
            var totalScore = 0.0f; //当前总分
            var ids = "0"; //当前做题的id
            for (var i = 0; i < QueInfos.Count; i++)
            {
                //Debug.Log("问题的类型：" + QueInfos[i].quetype);
                List<AnsInfo> ansInfos;
                if (QueInfos[i].quetype == 0 || QueInfos[i].quetype == 2 || QueInfos[i].quetype == 5 || QueInfos[i].quetype == 7) //客观题: 单选，判断，随机单选，公式题
                {
                    if (QueInfos[i].ansdata == null)
                    {
                        QueInfos[i].ansdata = GetAnsInfosByQueId(QueInfos[i].id, true);
                    }
                    ansInfos = QueInfos[i].ansdata;
                    QueInfos[i].ischeck = 1;
                    //判断题目的格式是否正确
                    var isRight = QueInfos[i].quetype == 0 || QueInfos[i].quetype == 2 ||
                                  ansInfos.Count >= 4 &&
                                  (QueInfos[i].quetype == 5 || QueInfos[i].quetype == 7);
                    //Debug.Log("题目的格式是否正确：" + isRight);
                    for (var j = 0; j < ansInfos.Count; j++)
                    {
                        if (ansInfos[j].ischoose != Convert.ToBoolean(ansInfos[j].isright))
                        {
                            isRight = false;
                            break;
                        }
                    }
                    if (isRight)
                    {
                        //Debug.LogError("答对题目的id:"+QueInfos[i].id+QueInfos[i].content);
                        objScore +=(float)QueInfos[i].score;//修改，从float？转换为float
                        ids += ";" + QueInfos[i].id;
                    }
                    QueInfos[i].isright = Convert.ToInt32(isRight);
                }
                else if (QueInfos[i].quetype == 1 || QueInfos[i].quetype == 6) //多选题的判断
                {
                    if (QueInfos[i].ansdata == null)
                    {
                        QueInfos[i].ansdata = GetAnsInfosByQueId(QueInfos[i].id, true);
                    }
                    //Debug.Log("单项得分是：" + QueInfos[i].singlescore);
                    ansInfos = QueInfos[i].ansdata;
                    var isRight = ansInfos.Count >= 4;
                    var isAllRight = true; //是否全选对了
                    float score = 0; //得分
                    for (var j = 0; j < ansInfos.Count; j++)
                    {
                        if (ansInfos[j].isright == 0 && ansInfos[j].ischoose)
                        {
                            //说明选择了错误的答案
                            isRight = false;
                            break;
                        }
                        if (ansInfos[j].isright == 1 && ansInfos[j].ischoose == false)
                        {
                            isAllRight = false; //没有全选对
                        }
                        if (ansInfos[j].isright == 1 && ansInfos[j].ischoose)
                        {
                            score += QueInfos[i].singlescore;
                        }
                    }
                    if (isAllRight && isRight) //全对
                    {
                        objScore +=(float)QueInfos[i].score;//修改，从float？转换为float
                        ids += ";" + QueInfos[i].id;
                    }
                    else if (!isAllRight && isRight) //选择了部分答案
                    {
                        objScore += score;
                    }
                    QueInfos[i].isright = Convert.ToInt32(isAllRight);
                }
                else //主观题，填空，简答
                {
                    if (QueInfos[i].ansdata == null)
                    {
                        QueInfos[i].ansdata = GetAnsInfosByQueId(QueInfos[i].id, true);
                    }
                    ansInfos = QueInfos[i].ansdata;
                    if (ansInfos.Count > 0 && ansInfos[0].content != null && ansInfos[0].content == ansInfos[0].userans &&
                        ansInfos[0].ischoose)
                    {
                        QueInfos[i].ischeck = 1;
                        QueInfos[i].isright = 1;
                        ids += ";" + QueInfos[i].id;
                        subScore += (float)QueInfos[i].score;//修改，从float？转换为float
                    }
                    else
                    {
                        QueInfos[i].ischeck = 0;
                        subUnKnow += (float)QueInfos[i].score;//修改，从float？转换为float
                    }
                }
                yield return new WaitForEndOfFrame();
            }
            totalScore =objScore +subScore;
            var dict = NetManager.Instance.GetDict();
            if (examType != ExamType.WrongExercise)
            {
                //发送分数
                //dict.Add("objscore", objScore);
                //dict.Add("subscore", subScore);
                //dict.Add("subunknow", subUnKnow);
                //发送当前的总分
                dict.Add("totalscore", totalScore);
                //添加试卷信息
                dict.Add("examname", ExamName.text);
                dict.Add("examid", examId);
                dict.Add("quedata", ClearnQueInfos(QueInfos, ClearnAnsInfos(RamdonedAnsInfos)));
                dict.Add("type", (int)examType);
                submitPaperInfo = dict;
                for (int i = 0; i < 100; i++)
                {
                    int temp = i;
                    NetManager.Instance.SendRequest(RequestType.SubmitPaper, dict, () =>
                    {
                        successNum += 1;
                        Debug.LogWarning("提交试卷成功的次数:" + successNum);
                    },dicts=> {
                        failedNum += 1;
                        Debug.LogError("提交试卷失败的次数:" + failedNum);
                    });
                    if (i == 99)
                    {
                        Destroy(tsf.gameObject);
                    }
                }                        
            }
            else //错题练习
            {
                dict.Add("id", ids);
                if (CollectPanel._Instance.AutoRemoveToggle.isOn)
                {
                    NetManager.Instance.SendRequest(RequestType.ClearErrorList, dict, () =>
                    {
                        //显示分数界面并且退出该界面 
                        Destroy(tsf.gameObject);
                        var panel = CreatePanel(PanelType.ExamReslutPanel).GetComponent<ExamReslutPanel>();
                        panel.Init(objScore, subScore, subUnKnow, totalScore, examType);
                        //todo 删除本地的数据
                        CollectPanel._Instance.OnExercise(ids);
                    });
                }
                else
                {
                    Destroy(tsf.gameObject);
                    var panel = CreatePanel(PanelType.ExamReslutPanel).GetComponent<ExamReslutPanel>();
                    panel.Init(objScore, subScore, subUnKnow, totalScore, examType);
                }
            }
        }

        /// <summary>
        /// 提交试卷的压力测试
        /// </summary>
        private void SubmitPaperTest() {
            StartCoroutine(testSubmit());
        }


        /// <summary>
        ///     提交按钮的点击事件
        /// </summary>
        private void OnSubmitButtonClick()
        {
            var panel = CreatePanel(PanelType.TipPanel).GetComponent<TipPanel>();
            switch (examType)
            {
                case ExamType.Exam:
                    panel.Init("提交试卷后，将无法继续进行考试，是否提交？", () =>
                    {
                        try
                        {
                            StartCoroutine(SubmitPaper());
                        }
                        catch (Exception exception)
                        {
                            //todo 退出加载循环界面
                            UIManager._Instance.ExitPanel("LoadingLoop(Clone)");
                            Debug.Log("提交试卷错误："+exception.ToString());
                        }
                       
                    });
                    break;
                default:
                    var tipText = !IsFinishPaper() ? "您有未作答的题目,是否提交？" : "提交试卷后，将无法继续进行考试，是否提交？";
                    panel.Init(tipText, () => { StartCoroutine(SubmitPaper()); });
                    break;
            }
        }

        private bool IsFinishPaper()
        {
            var isFinish = true;
            for (var i = 0; i < QueInfos.Count; i++)
            {
                if (!Convert.ToBoolean(QueInfos[i].isselect)) //说明有未选择的
                {
                    isFinish = false;
                    break;
                }
            }
            return isFinish;
        }
        
        /*处理问题的顺序 */
        private List<QueInfo> HandleQuestion(List<QueInfo>questions){
            List<QueInfo>result=new List<QueInfo>();
            List<QueInfo>singleSelect=new List<QueInfo>();//单选
            List<QueInfo>mulitySelect=new List<QueInfo>();//多选
            List<QueInfo>judge=new List<QueInfo>();//判断
            List<QueInfo>empty=new List<QueInfo>();//填空
            List<QueInfo>shortAnswer=new List<QueInfo>();//简答
            //题目类型 0:单选 1:多选 2:判断 3：填空 4：简答 5：随机单选 6：随机多选 7：随机公式(单选)
            for (int i = 0; i < questions.Count; i++)
            {
                switch(questions[i].quetype){
                    case 0:
                        singleSelect.Add(questions[i]);
                        break;
                    case 1:
                        mulitySelect.Add(questions[i]);
                        break;
                    case 2:
                        judge.Add(questions[i]);
                        break;
                    case 3:
                        empty.Add(questions[i]);
                        break;
                    case 4:
                        shortAnswer.Add(questions[i]);
                        break;
                    case 5:
                        singleSelect.Add(questions[i]);
                        break;
                    case 6:
                        mulitySelect.Add(questions[i]);
                        break;  
                    case 7:
                        singleSelect.Add(questions[i]);
                        break;      
                }
            }   
            result.AddRange(singleSelect);
            result.AddRange(mulitySelect);
            result.AddRange(judge);
            result.AddRange(empty);
            result.AddRange(shortAnswer);
            return result;
        }


        /// <summary>
        ///     初始化
        /// </summary>
        /// <param name="type"></param>
        /// <param name="ansInfos"></param>
        /// <param name="examid"></param>
        /// <param name="onSubmitPaper"></param>
        /// <param name="isCheckScore"></param>
        /// <param name="score"></param>
        /// <param name="exanName"></param>
        /// <param name="time"></param>
        /// <param name="queInfos"></param>
        public void Init(ExamType type, string exanName, int time, List<QueInfo> queInfos, List<AnsInfo> ansInfos,
            int? examid, Action<float> onSubmitPaper = null, bool isCheckScore = false, float score = 0)
        {
            this.isCheckScore = isCheckScore;
            isInit = true;
            OnSubmitPaper = onSubmitPaper;
            examType = type; //记录考试的类型
            AnsInfos = ansInfos; //记录答案列表
            QueInfos = HandleQuestion(queInfos);
            examId = examid;
            if (isCheckScore) //如果是查询成绩
            {
                TimeObj.gameObject.SetActive(false);
                ExamName.text = exanName;
                StartCoroutine(CoroutineInit(time, true));
                CheckLable.gameObject.SetActive(true);
                ExamLable.gameObject.SetActive(false);
                ScoreLable.gameObject.SetActive(true);
                ScoreText.text = score.ToString();
                SubmitButton.gameObject.SetActive(false);
                CreatePanel(PanelType.CheckScoreTipPanel);
                return;
            }
            CheckLable.gameObject.SetActive(false);
            ExamLable.gameObject.SetActive(true);
            ScoreLable.gameObject.SetActive(false);
            switch (type)
            {
                case ExamType.Exam: //正常考试
                    TimeObj.gameObject.SetActive(true);
                    ExamName.text = exanName;
                    StartCoroutine(CoroutineInit(time, false, type));
                    break;
                case ExamType.HomeWork: //作业
                    TimeObj.gameObject.SetActive(false);
                    ExamName.text = exanName;
                    StartCoroutine(CoroutineInit(time, false));
                    break;
                case ExamType.Mock: //模拟考试
                    TimeObj.gameObject.SetActive(true);
                    ExamName.text = exanName;
                    StartCoroutine(CoroutineInit(time, false));
                    break;
                case ExamType.WrongExercise: //错题练习
                    TimeObj.gameObject.SetActive(false);
                    ExamName.text = exanName;
                    StartCoroutine(CoroutineInit(time, false, type));
                    break;
            }
        }

        /// <summary>
        /// 是否触发了登入超时
        /// </summary>
        /// <param name="trigger"></param>
        private void LoginTimeOut(bool trigger)
        {
            stopTimer = trigger;
        }

        /// <summary>
        ///     更新
        /// </summary>
        protected override void Update()
        {
            if (examType == ExamType.Exam || examType == ExamType.Mock)
            {
                if (examTime > 0)
                {
                    if (stopTimer)
                    {
                        return;
                    }
                    examTime -= Time.deltaTime;
                    TimeText.text = TimerTool.GetTime03(examTime);
                }
                else if (isInit)
                {
                    //考试结束,提交试卷,将时间设置为0
                    TimeText.text = TimerTool.GetTime03(0);
                    //if (isSubmit) return;
                    try
                    {
                        //弹出必须提交试卷的界面
                        SubmitPaperMask.gameObject.SetActive(true);
                    }
                    catch (Exception e)
                    {
                        UIManager._Instance.ExitPanel("LoadingLoop(Clone)");
                        Debug.Log("提交试卷错误：" + e);
                    }
                }
            }
        }


        /// <summary>
        ///     初始化时间
        /// </summary>
        private void InitTime(int second)
        {
            examTime = second;
            TimeText.text = TimerTool.GetTime03(second);
        }

        public PaperGuideItem GetGuideItemById(int queId)
        {
            PaperGuideItem guideItem = null;
            for (var i = 0; i < GuideItems.Count; i++)
            {
                if (GuideItems[i].QueId == queId)
                {
                    guideItem = GuideItems[i];
                    break;
                }
            }
            return guideItem;
        }

        /// <summary>
        ///     通过问题的Id得到答案列表
        /// </summary>
        /// <param name="queId"></param>
        /// <param name="isRandomed"></param>
        /// <returns></returns>
        public List<AnsInfo> GetAnsInfosByQueId(int queId, bool isRandomed) //to 随机后的数组有bug
        {
            var ansInfos = new List<AnsInfo>();
            if (!isRandomed)
            {
                for (var i = 0; i < AnsInfos.Count; i++)
                {
                    if (AnsInfos[i] != null)
                    {
                        if (AnsInfos[i].queid == queId)
                        {
                            ansInfos.Add(AnsInfos[i]);
                        }
                    }
                }
            }
            else
            {
                for (var i = 0; i < RamdonedAnsInfos.Count; i++)
                {
                    if (RamdonedAnsInfos[i].queid == queId)
                    {
                        ansInfos.Add(RamdonedAnsInfos[i]);
                    }
                }
            }
            return ansInfos;
        }
    

        /// <summary>
        ///     实例化题目
        /// </summary>
        /// <param name="second"></param>
        /// <param name="isCheckScore"></param>
        /// <returns></returns>
        private IEnumerator CoroutineInit(int second, bool isCheckScore, ExamType examType = ExamType.Null)
        {
            //检查是否有公式题目
            InitTime(second);
            CheckOutFormula(QueInfos);
            InitTitleInfos(QueInfos);

            var titleNum = examType != ExamType.WrongExercise ? titleInfos.Count : 0;
            var index = 0; //总的题目数
            var queIndex = 0; //问题index
            var titleIndex = 0; //标题的index
            var pageNum = (titleNum + QueInfos.Count)%pageQueNum == 0
                ? QueInfos.Count/pageQueNum + 1
                : QueInfos.Count/pageQueNum + 2; //避免添加标题后出现的错误
            titleTypes.Clear();
            var truePage = 0;
            for (var i = 0; i < pageNum; i++)
            {
                var pageButton = Instantiate(PageButton, PageButton.transform.parent);
                pageButton.gameObject.SetActive(true);
                pageButton.transform.Find("Text").GetComponent<Text>().text = (i + 1).ToString();
                pageButtons.Add(pageButton);
                var page = Instantiate(ScrollView_Paper, ScrollView_Paper.transform.parent).transform;
                page.gameObject.SetActive(true);
                page.SetAsFirstSibling();
                scrollView_Papers.Add(page);
                truePage++;
                for (var j = 0; j < pageQueNum; j++)
                {
                    index++;
                    //....................这里有个bug..................
                    // Debug.Log("index:" + index);
                    // Debug.Log("titleNum:" + titleNum);
                    // Debug.Log("queNum:" + queIndex + "QueInfos.count:" + QueInfos.Count);
                    if (index > QueInfos.Count + titleNum)
                    {
                        CreateEmptyItem(page.transform.Find("Viewport/Content_Paper"));
                        if (i != 0)
                        {
                            page.gameObject.SetActive(false);
                        }
                        else
                        {
                            nowPage = page;
                            nowClickButton = pageButton;
                            nowClickButton.GetComponent<ButtonSprite>().SetPressedSprite();
                            nowClickButton.GetComponent<Image>().color = Color.yellow;
                        }
                        pageButton.onClick.AddListener(() =>
                        {
                            pageButton.GetComponent<ButtonSprite>().SetPressedSprite();
                            pageButton.GetComponent<Image>().color = Color.yellow;
                            if (nowPage != null && nowPage != page)
                            {
                                nowClickButton.GetComponent<ButtonSprite>().SetNormalSprite();
                                nowClickButton.GetComponent<Image>().color = Color.white;
                                nowPage.gameObject.SetActive(false);
                            }
                            nowPage = page;
                            nowClickButton = pageButton;
                            page.gameObject.SetActive(true);
                            //page.Find("Scrollbar_Paper").GetComponent<Scrollbar>().value = 1;
                        });
                        Debug.LogWarning("跳出选项了.................");
                        yield break;
                    }
                    //插入标题
                    var isInsertTitle = false;
                    if (examType != ExamType.WrongExercise)
                    {
                        isInsertTitle = InsertTitle(page.transform.Find("Viewport/Content_Paper"),
                            QueInfos[queIndex], titleIndex);
                    }
                    if (isInsertTitle)
                    {
                        titleIndex++;
                    }
                    else
                    {
                        //说明这里多执行了一次
                        queIndex++; //
                        //初始化Guide
                        var tsf_Guide = CreateItem(ItemType.PaperGuideItem);
                        tsf_Guide.SetParent(Content_Guide);
                        tsf_Guide.localPosition = Vector3.zero;
                        tsf_Guide.localScale = Vector3.one;
                        var item_Paper = tsf_Guide.GetComponent<PaperGuideItem>();
                        item_Paper.Init(queIndex, index, QueInfos[queIndex - 1], isCheckScore); //编号从1开始
                        GuideItems.Add(item_Paper);

                        //初始化问题
                        var queitem = CreateItem(ItemType.QueItem);
                        queitem.SetParent(page.transform.Find("Viewport/Content_Paper"));
                        queitem.localPosition = Vector3.zero;
                        queitem.localScale = Vector3.one;
                        var item = queitem.GetComponent<QueItem>();
                        item.Init(queIndex, QueInfos[queIndex - 1], item_Paper, examType, isCheckScore);
                    }
                    yield return 0;
                }
                //注册按钮事件
                pageButton.onClick.AddListener(() =>
                {
                    pageButton.GetComponent<ButtonSprite>().SetPressedSprite();
                    pageButton.GetComponent<Image>().color = Color.yellow;
                    if (nowPage != null && nowPage != page)
                    {
                        nowClickButton.GetComponent<ButtonSprite>().SetNormalSprite();
                        nowClickButton.GetComponent<Image>().color = Color.white;
                        nowPage.gameObject.SetActive(false);
                    }
                    nowPage = page;
                    nowClickButton = pageButton;
                    page.gameObject.SetActive(true);
                    //page.Find("Scrollbar_Paper").GetComponent<Scrollbar>().value = 1;
                });
                CreateEmptyItem(page.transform.Find("Viewport/Content_Paper"));
                if (i != 0)
                {
                    page.gameObject.SetActive(false);
                }
                else
                {
                    nowPage = page;
                    nowClickButton = pageButton;
                    nowClickButton.GetComponent<ButtonSprite>().SetPressedSprite();
                    nowClickButton.GetComponent<Image>().color = Color.yellow;
                }
            }
        }

        /// <summary>
        ///     初始化题目标题的信息
        /// </summary>
        private void InitTitleInfos(List<QueInfo> queInfos)
        {
            var titleInfo1 = new TitleInfo {Name = TitleType.单项选择题.ToString()}; //单选
            var titleInfo2 = new TitleInfo {Name = TitleType.多项选择题.ToString()}; //多选
            var titleInfo3 = new TitleInfo {Name = TitleType.判断题.ToString()}; //判断题
            var titleInfo4 = new TitleInfo {Name = TitleType.填空题.ToString()}; //填空题
            var titleInfo5 = new TitleInfo {Name = TitleType.简答题.ToString()}; //简答题
            for (var i = 0; i < queInfos.Count; i++)
            {
                var type = Convert.ToInt32(queInfos[i].quetype);
                if (type == 0 || type == 5 || type == 7) //单选 随机单选 公式 (单选题题型)
                {
                    titleInfo1.Count++;
                    titleInfo1.Score = queInfos[i].score;
                }
                if (type == 1 || type == 6) //多选题 随机多选 (多选题题型)
                {
                    titleInfo2.Count++;
                    titleInfo2.Score = queInfos[i].score;
                    titleInfo2.SingleScore = queInfos[i].singlescore;
                }
                if (type == 2) //(判断题)
                {
                    titleInfo3.Count++;
                    titleInfo3.Score = queInfos[i].score;
                }
                if (type == 3) //(填空题)
                {
                    titleInfo4.Count++;
                    titleInfo4.Score = queInfos[i].score;
                }
                if (type == 4) //简答
                {
                    titleInfo5.Count++;
                    titleInfo5.Score =queInfos[i].score;
                }
            }
            if (titleInfo1.Count != 0) titleInfos.Add(titleInfo1);
            if (titleInfo2.Count != 0) titleInfos.Add(titleInfo2);
            if (titleInfo3.Count != 0) titleInfos.Add(titleInfo3);
            if (titleInfo4.Count != 0) titleInfos.Add(titleInfo4);
            if (titleInfo5.Count != 0) titleInfos.Add(titleInfo5);
        }

        private TitleInfo GetTitleInfo(string name)
        {
            TitleInfo info = null;
            for (var i = 0; i < titleInfos.Count; i++)
            {
                if (titleInfos[i].Name == name)
                {
                    info = titleInfos[i];
                    break;
                }
            }
            return info;
        }

        /// <summary>
        ///     插入题目的标题
        /// </summary>
        /// <param name="parent">标题的父亲</param>
        /// <param name="info"></param>
        /// <param name="titleIndex"></param>
        private bool InsertTitle(Transform parent, QueInfo info, int titleIndex)
        {
            //Debug.Log("type:" + info.quetype);
            var insert = false;
            if (info.quetype != queType)
            {
                queType = Convert.ToInt32(info.quetype);
                var type = info.quetype;
                TitleInfo titleInfo = null;
                var titleName = "";
                if (type == 0 || type == 5 || type == 7) //单选 随机单选 公式 (单选题题型)
                {
                    titleName = TitleType.单项选择题.ToString();
                    if (!ContainTitle(titleName))
                    {
                        titleTypes.Add(titleName);
                        titleInfo = GetTitleInfo(titleName);
                        insert = InsertTitle(titleInfo, titleIndex, parent);
                    }
                }
                if (type == 1 || type == 6) //多选题 随机多选 (多选题题型)
                {
                    titleName = TitleType.多项选择题.ToString();
                    if (!ContainTitle(titleName))
                    {
                        titleTypes.Add(titleName);
                        titleInfo = GetTitleInfo(titleName);
                        insert = InsertTitle(titleInfo, titleIndex, parent);
                    }
                }
                if (type == 2) //(判断题)
                {
                    titleName = TitleType.判断题.ToString();
                    if (!ContainTitle(titleName))
                    {
                        titleTypes.Add(titleName);
                        titleInfo = GetTitleInfo(titleName);
                        insert = InsertTitle(titleInfo, titleIndex, parent);
                    }
                }
                if (type == 3) //(填空题)
                {
                    titleName = TitleType.填空题.ToString();
                    if (!ContainTitle(titleName))
                    {
                        titleTypes.Add(titleName);
                        titleInfo = GetTitleInfo(titleName);
                        insert = InsertTitle(titleInfo, titleIndex, parent);
                    }
                }
                if (type == 4) //简答
                {
                    titleName = TitleType.简答题.ToString();
                    if (!ContainTitle(titleName))
                    {
                        titleTypes.Add(titleName);
                        titleInfo = GetTitleInfo(titleName);
                        insert = InsertTitle(titleInfo, titleIndex, parent);
                    }
                }
            }
            return insert;
        }

        /// <summary>
        ///     插入标题
        /// </summary>
        /// <param name="titleInfo"></param>
        /// <param name="titleIndex"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        private bool InsertTitle(TitleInfo titleInfo, int titleIndex, Transform parent)
        {
            titleIndex++;
            var tsf = CreateItem(ItemType.TitleItem);
            tsf.SetParent(parent);
            tsf.localScale = Vector3.one;
            var index = "";
            switch (titleIndex)
            {
                case 1:
                    index = "一";
                    break;
                case 2:
                    index = "二";
                    break;
                case 3:
                    index = "三";
                    break;
                case 4:
                    index = "四";
                    break;
                case 5:
                    index = "五";
                    break;
            }
            switch (titleInfo.Name)
            {
                case "单项选择题":
                    tsf.GetComponent<Text>().text = string.Format("{0}.{1}：共{2}小题，每小题{3}分，共{4}分，每题备选答案中只有1个最符合题意",
                        index, titleInfo.Name, titleInfo.Count, titleInfo.Score, titleInfo.Score*titleInfo.Count);
                    break;
                case "多项选择题":
                    tsf.GetComponent<Text>().text =
                        string.Format(
                            "{0}.{1}：共{2}小题，每小题{3}分，共{4}分，每题的备选项中，有2个或2个以上符合题意，至少有1个错项，错选，本题不得分；少选，所选的每个选项得{5}分",
                            index, titleInfo.Name, titleInfo.Count, titleInfo.Score, titleInfo.Score*titleInfo.Count,
                            titleInfo.SingleScore);
                    break;
                case "填空题":
                    tsf.GetComponent<Text>().text = string.Format("{0}.{1}：共{2}小题，每小题{3}分，共{4}分",
                        index, titleInfo.Name, titleInfo.Count, titleInfo.Score, titleInfo.Score*titleInfo.Count);
                    break;
                case "简答题":
                    tsf.GetComponent<Text>().text = string.Format("{0}.{1}：共{2}小题，每小题{3}分，共{4}分",
                        index, titleInfo.Name, titleInfo.Count, titleInfo.Score, titleInfo.Score*titleInfo.Count);
                    break;
                case "判断题":
                    tsf.GetComponent<Text>().text = string.Format("{0}.{1}：共{2}小题，每小题{3}分，共{4}分,每题备选答案中只有1个最符合题意",
                        index, titleInfo.Name, titleInfo.Count, titleInfo.Score, titleInfo.Score*titleInfo.Count);
                    break;
            }
            return true;
        }


        /// <summary>
        ///     是否包含标题
        /// </summary>
        /// <param name="title"></param>
        /// <returns></returns>
        private bool ContainTitle(string title)
        {
            var contain = false;
            for (var i = 0; i < titleTypes.Count; i++)
            {
                if (titleTypes[i] == title)
                {
                    contain = true;
                    break;
                }
            }
            return contain;
        }

        private void CreateEmptyItem(Transform content)
        {
            //实例化一个Empty模型
            var lastQueItem = content.GetChild(content.childCount - 1);
            var itemHeight = lastQueItem.GetComponent<RectTransform>().rect.height;
            var viewPortHeight = ScrollView_Paper.transform.GetChild(0).GetComponent<RectTransform>().rect.height;
            if (itemHeight >= viewPortHeight) return;
            var tsf = CreateItem(ItemType.EmptyItem);
            tsf.SetParent(content);
            var layoutElement = tsf.GetComponent<LayoutElement>();
            layoutElement.preferredHeight = viewPortHeight - itemHeight - 20;
        }

        /// <summary>
        ///     检查公式题型
        /// </summary>
        /// <param name="queInfos"></param>
        private void CheckOutFormula(List<QueInfo> queInfos)
        {
            for (var i = 0; i < queInfos.Count; i++)
            {
                if (queInfos[i].quetype == 7 && !string.IsNullOrEmpty(queInfos[i].formulas)) //说明是公式题
                {
                    if (queInfos[i].ansdata == null)
                    {
                        queInfos[i].ansdata = new List<AnsInfo>();
                    }
                    queInfos[i].ansdata.Clear();
                    var formulas = queInfos[i].formulas.Split('|'); //0#A+B+C+D|1#A-C+B+D 0表示错误，1表示正确
                    var args = ChangeArgsFormat(queInfos[i].args.Split('|')); //args 可能是A=(1,100) 可能是A={1,3,5} 
                    for (var j = 0; j < formulas.Length; j++)
                    {
                        var temp = formulas[j].Split('#');
                        var formula = FormulaTool.Formula(temp[1], args); //得到具体的计算公式
                        var calculator = new FormulaCalculator();
                        var ansInfo = new AnsInfo();
                        ansInfo.content = calculator.GetResult(formula, Convert.ToInt32(queInfos[i].@decimal)); //计算结果
                        //Debug.Log("formula:" + formula + "   ansInfo.Content:" + ansInfo.content);
                        ansInfo.isright = Convert.ToInt32(temp[0]);
                        ansInfo.queid = queInfos[i].id;
                        queInfos[i].ansdata.Add(ansInfo);
                    }
                    if (string.IsNullOrEmpty(queInfos[i].oldcontent))
                    {
                        queInfos[i].oldcontent = queInfos[i].content;
                    }
                    queInfos[i].content = queInfos[i].oldcontent;
                    for (var j = 0; j < args.Length; j++)
                    {
                        var temp = args[j].Split('_');
                        queInfos[i].content = queInfos[i].content.Replace(temp[0], temp[1]);
                    }
                }
            }
        }

        /// <summary>
        ///     随机参数并转化参数的格式
        /// </summary>
        private string[] ChangeArgsFormat(string[] args)
        {
            var value = new string[args.Length];
            for (var i = 0; i < args.Length; i++)
            {
                var temp = args[i].Split('=');
                if (temp.Length == 2)
                {
                    if (temp[1].Contains("{")) //数组
                    {
                        var sub = temp[1].Substring(1, temp[1].Length - 2); //除去大括号
                        var nums = sub.Split(','); //用'，'分割参数
                        var indexs = RamdomTool.GetRandoms(1, 0, nums.Length - 1); //参数的集合
                        value[i] = temp[0] + "_" + nums[indexs[0]];
                    }
                    else //范围
                    {
                        var @decimal = Convert.ToInt32(temp[1].Split('#')[1]); //取得的值保留的位数
                        var sub = temp[1].Split('#')[0].Substring(1, temp[1].Split('#')[0].Length - 2); //除去小括号
                        var nums = sub.Split(','); //用'，'分割参数
                        if (@decimal == 0) //说明取值的结果为整数
                        {
                            var random = new Random();
                            var num = random.Next(Convert.ToInt32(nums[0]), Convert.ToInt32(nums[1]));
                            value[i] = temp[0] + "_" + num;
                        }
                        else //小数
                        {
                            var num = UnityEngine.Random.Range(Convert.ToSingle(nums[0]), Convert.ToSingle(nums[1]));
                            var calculator = new FormulaCalculator();
                            value[i] = temp[0] + "_" + calculator.NumberAround(num, @decimal);
                        }
                    }
                }
            }
            Debug.Log("value:" + value);
            return value;
        }


        /// <summary>
        ///     通过题号定位题目的位置
        /// </summary>
        /// <param name="queNum"></param>
        private void LocationByIndex(int queNum, int pageNum)
        {
            Debug.Log("queNum:" + queNum);
            float posHight = 0;
            var content_Paper = scrollView_Papers[pageNum].transform.Find("Viewport/Content_Paper");
            var Scrollbar_Paper = scrollView_Papers[pageNum].transform.Find("Scrollbar_Paper").GetComponent<Scrollbar>();
            var contentHight = content_Paper.GetComponent<RectTransform>().rect.height;
            var scrollViewHight =
                scrollView_Papers[pageNum].transform.GetChild(0).GetComponent<RectTransform>().rect.height;
            contentHight = contentHight - scrollViewHight; //实际能够滑动的滑动条长度
            for (var i = 0; i < queNum; i++) //包含试卷的标题
            {
                float posValue = 0;
                posValue = content_Paper.GetChild(i).GetComponent<RectTransform>().rect.height;
                if (queNum == content_Paper.childCount)
                {
                    posHight += posValue;
                }
                else
                {
                    posHight += posValue + 20;
                }
            }
            var value = posHight/contentHight;
            DOTween.To(() => Scrollbar_Paper.value, x => Scrollbar_Paper.value = x, 1 - value, EaseTime).SetEase(Ease);
        }

        /// <summary>
        ///     通过题号定位题目的位置
        /// </summary>
        /// <param name="index"></param>
        private IEnumerator LocationByIndex(int index)
        {
            var pageNum = 0;
            if (index%pageQueNum == 0)
            {
                pageNum = index/pageQueNum - 1;
            }
            else
            {
                pageNum = Convert.ToInt32((index/pageQueNum).ToString().Split('.')[0]);
            }
            var queNum = index - pageNum*pageQueNum;
            //Debug.Log("index:"+index+"pageNum:"+pageNum+"__queNum:"+queNum);
            pageButtons[pageNum].onClick.Invoke();
            yield return 0;
            LocationByIndex(queNum, pageNum);
        }

        public void StartLocationByIndex(int index)
        {
            StartCoroutine(LocationByIndex(index));
        }
    }
}